/*
   Copyright (c) 2011 Mizar Tools Contributors (mizartools.org)

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
/*  Contributors :
 *	2011-02-04 Marco Riccardi - initial implementation
 *
 */
package org.mizartools.system.utility;

import java.util.HashMap;

import org.mizartools.system.Article;
import org.mizartools.system.xml.ConstrCount;

class SignatureItem {

	private static HashMap<String, SignatureItem> hashMapSignatureItem = new HashMap<String, SignatureItem>();
	
	public final String articleId;
	public final int nrG;
	public final int nrK;
	public final int nrL;
	public final int nrM;
	public final int nrR;
	public final int nrU;
	public final int nrV;
	
	private SignatureItem(Article article) {
		articleId = article.getAid();
		int intG = 0, intK = 0, intL = 0, intM = 0, intR = 0, intU = 0, intV = 0;
		for (ConstrCount constrCount : article.getConstructors().getConstrCounts().getConstrCountList()) {
			switch (constrCount.getKind()){
			case G : intG = constrCount.getNr(); break;
			case K : intK = constrCount.getNr(); break;
			case L : intL = constrCount.getNr(); break;
			case M : intM = constrCount.getNr(); break;
			case R : intR = constrCount.getNr(); break;
			case U : intU = constrCount.getNr(); break;
			case V : intV = constrCount.getNr(); break;
			}
		}
		nrG = intG;
		nrK = intK;
		nrL = intL;
		nrM = intM;
		nrR = intR;
		nrU = intU;
		nrV = intV;
	}
	
	public static SignatureItem getSignatureItem (Article article) {
		String aid = article.getAid();
		if (!hashMapSignatureItem.containsKey(aid)) {
			SignatureItem signatureItem = new SignatureItem(article);
			hashMapSignatureItem.put(aid, signatureItem);
		} 
		return hashMapSignatureItem.get(aid);
	}

}
